<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 *项目管理
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$manage_op=array('start','off');
if(in_array($_RQ['op'],$manage_op)){
	$id=intval($_RQ['id']);
	if(!$id){
		exi('请先选择信息！','error');
	}
}
$return['sex']=$this->sex;
$return['status']=$this->order_status;
if($_RQ['op']=='list'){
	$params=array();
	$params['uniacid']=$_SESSION['uniacid'];
	if(isset($_RQ['status'])){
		$params['status']=intval($_RQ['status']);
		$return['params']['status']=$_RQ['status'];
	}
	if(isset($_RQ['memberid'])){
		$params['memberid']=intval($_RQ['memberid']);
		$return['params']['memberid']=$_RQ['memberid'];
	}
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$total='';
	$list=pdo_getslice('jy_daibao_order',$params,array($pindex,$psize),$total,$fields,'','id desc');
	if($list){
		foreach($list as &$item){
			$item['member']=cfc('core')->member_show($item['mid']);
			$item['yewu']=pdo_get('jy_daibao_yewu',array('id'=>$item['yewuid'],'uniacid'=>$_SESSION['uniacid']),array('id','title'));
			$merch=json_decode($item['merchinfo'],true);
			$item['merch']=$merch;
		}
	}
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'tabs'=>array(
			array('op'=>'list','title'=>'服务订单'),
		),
		'list'=>array('data'=>'list','tip'=>'<red>[温馨提示]：这里显示服务订单情况</red>','edit'=>false,'list'=>array(
			array('name'=>'member','title'=>'会员信息','type'=>'member'),
			array('name'=>'merch.title','title'=>'公司名称','type'=>'string'),
			array('name'=>'fee','title'=>'费用','type'=>'string'),
			array('name'=>'yewu.title','title'=>'业务名称','type'=>'string'),
			array('name'=>'status','title'=>'状态','type'=>'radio','options'=>'status'),
			array('name'=>'createtime','title'=>'创建时间','type'=>'time'),
		),'action'=>array(
			array('title'=>'开始处理','type'=>'modal','op'=>'change','show'=>array('status'=>1)),
			array('title'=>'处理完成','type'=>'modal','op'=>'change3','show'=>array('status'=>2)),
		)),
		'search'=>array(
			array('name'=>'status','width'=>15,'title'=>'状态','type'=>'radio','options'=>'status'),
		)
	);
	$return['sex']=$this->sex;
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='change'){
	if($_RQ['postdata']){
		$post=get_postdata();
		$id=intval($post['id']);
		pdo_update('jy_daibao_order',array('status'=>2),array('id'=>intval($id),'uniacid'=>$_SESSION['uniacid']));
		exi('处理成功！','','list');
	}
	$item=pdo_get('jy_daibao_order',array('id'=>intval($_RQ['id']),'uniacid'=>$_SESSION['uniacid']));
	if(!$item){
		exi('指定订单不存在！','error');
	}
	$return['item']=$item;
	$return['htmls']=array(
		'type'=>'edit',
		'desc'=>'处理业务',
		'edit'=>array(
			array('type'=>'tip','title'=>'确定已接单，开始着手处理！'),
		),
	);
	exi($return);
}
if($_RQ['op']=='change3'){
	if($_RQ['postdata']){
		$post=get_postdata();
		$id=intval($post['id']);
		pdo_update('jy_daibao_order',array('status'=>3),array('id'=>intval($id),'uniacid'=>$_SESSION['uniacid']));
		exi('处理成功！','','list');
	}
	$item=pdo_get('jy_daibao_order',array('id'=>intval($_RQ['id']),'uniacid'=>$_SESSION['uniacid']));
	if(!$item){
		exi('指定订单不存在！','error');
	}
	$return['item']=$item;
	$return['htmls']=array(
		'type'=>'edit',
		'desc'=>'处理完成',
		'edit'=>array(
			array('type'=>'tip','title'=>'确定已处理完成！'),
		),
	);
	exi($return);
}
if($_RQ['op']=='del'){
	$del=trim($_RQ['del'],';');
	if($del){
		$del=explode(';',$del);
	}else{
		$del=array();
	}
	if($_RQ['id']){
		$del[]=$_RQ['id'];
	}
	foreach($del as $id){
		$id=intval($id);
		if($id){
			pdo_delete('jy_daibao_order',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
		}
	}
	exi('删除成功！');
}